<html>
<head><meta charset="utf-8"><title>Emitting lints mid typeck · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html">Emitting lints mid typeck</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221033568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221033568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221033568">(Dec 28 2020 at 02:01)</a>:</h4>
<p>I'm trying to add a lint to support migrations for <code>capture_disjoint_fields</code> ( it is a breaking feature). The best time (from a perf perspective)  to emit this information would be while we process closures in typechk.</p>
<p>I was reading through rustc dev guide and I see either a pre or a post typechk, is there a way to do it somewhere in the middle?</p>



<a name="221033986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221033986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221033986">(Dec 28 2020 at 02:13)</a>:</h4>
<p>Can you use <code>TyCtxt::struct_span_lint_hir</code>?</p>



<a name="221034150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221034150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221034150">(Dec 28 2020 at 02:16)</a>:</h4>
<p>I mean, you can have a lint that has no registered pass</p>



<a name="221034168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221034168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221034168">(Dec 28 2020 at 02:17)</a>:</h4>
<p>So during typeck you can "manually" emit the lint, instead of walking the crate afterwards as a separate pass</p>



<a name="221034209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221034209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221034209">(Dec 28 2020 at 02:18)</a>:</h4>
<p>Okay I didn't know that, I'll give it a shot, thanks <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="221034343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221034343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221034343">(Dec 28 2020 at 02:22)</a>:</h4>
<p>I think those are called hardwired lints</p>



<a name="221034352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221034352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221034352">(Dec 28 2020 at 02:22)</a>:</h4>
<p>See <code>rustc_lint_defs::builtin</code></p>



<a name="221035360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221035360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aman Arora <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221035360">(Dec 28 2020 at 02:55)</a>:</h4>
<p>Okay I think this will work for the most part. I'm wondering if there is a way to check if the lint is enabled before I perform the analysis, it is fair bit of work. </p>
<p>One thing I see is to call <code>tcx.lint_level_at_node(lint, hir_id);</code> and see if it's deny/warn before doing the required analysis and calling in <code>struct_span_lint_hir</code>. I'm curious if there is a function that already does it that I'm not aware of</p>



<a name="221066103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221066103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221066103">(Dec 28 2020 at 15:01)</a>:</h4>
<p>I had to do something like this for <code>#![feature(unsafe_block_in_unsafe_fn)]</code></p>



<a name="221066303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Emitting%20lints%20mid%20typeck/near/221066303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Emitting.20lints.20mid.20typeck.html#221066303">(Dec 28 2020 at 15:03)</a>:</h4>
<p>For my case I added <a href="https://github.com/rust-lang/rust/pull/71862/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R777-R779">a little helper function</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>